package com.shuoyue.ycgk.ui.mine.mypaperset;

import com.shuoyue.ycgk.base.BaseModel;
import com.shuoyue.ycgk.base.BasePresenter;
import com.shuoyue.ycgk.base.BaseResult;
import com.shuoyue.ycgk.base.BaseView;
import com.shuoyue.ycgk.base.ListWithPage;
import com.shuoyue.ycgk.entity.Paper;
import com.shuoyue.ycgk.entity.PaperSet;
import com.shuoyue.ycgk.net.RetrofitClient;
import com.shuoyue.ycgk.net.base.ApiSubscriber;
import com.shuoyue.ycgk.net.gsondefaultadapter.Optional;

import java.util.List;

import io.reactivex.Observable;

public interface MyPaperContract {
    interface View extends BaseView {
        void setPaperSet(ListWithPage<PaperSet> paperSets);
    }

    class Presenter extends BasePresenter<View> {
        Model model = new Model();


        public void getMyPaperSet(int moduledId, int page) {
            if (moduledId == 0) {
                apply(model.getMyPauchesPaperSet(page))
                        .subscribe(new ApiSubscriber<Optional<ListWithPage<PaperSet>>>(mView, this) {
                            @Override
                            public void onNext(Optional<ListWithPage<PaperSet>> listOptional) {
                                super.onNext(listOptional);
                                mView.setPaperSet(listOptional.getIncludeNull());
                            }
                        });
            } else
                apply(model.getMyCollectPaperSet(moduledId,page))
                        .subscribe(new ApiSubscriber<Optional<ListWithPage<PaperSet>>>(mView, this) {
                            @Override
                            public void onNext(Optional<ListWithPage<PaperSet>> listOptional) {
                                super.onNext(listOptional);
                                mView.setPaperSet(listOptional.getIncludeNull());
                            }
                        });
        }


    }

    class Model extends BaseModel {


        /**
         * 题库包列表->购买
         *
         * @return
         */
        Observable<BaseResult<ListWithPage<PaperSet>>> getMyPauchesPaperSet(int page) {
            return RetrofitClient.getInstance().getApi().getMyPauchesPaperSet(page);
        }

        /**
         * 题库包列表->收藏
         *
         * @return
         */
        Observable<BaseResult<ListWithPage<PaperSet>>> getMyCollectPaperSet(int moduledId, int page) {
            return RetrofitClient.getInstance().getApi().getMyCollectPaperSet(moduledId, page);
        }

    }
}
